from django.db import models
from luffyapi.utils.models import BaseModel


# Create your models here.

class Banner(BaseModel):
    """ 轮播广告图模型 """
    title = models.CharField(max_length=500, verbose_name='广告标题')
    link = models.CharField(max_length=500, verbose_name='广告链接')  # 广告链接，点击跳转到具体页面
    image_url = models.ImageField(upload_to='banner', null=True, blank=True, max_length=255, verbose_name='广告图片')
    # upload_to: 设置上传文件的保存的子目录，将来上传文件时会保存到media下面的banner文件夹下，这个字段本身存储图片地址。
    # uploads/banner/图片.png
    # 一般情况下，图片资源我们只是存储其路径。（如果图片特别小，有的公司也会把图片数据存在数据库）
    remark = models.TextField(verbose_name='备注信息')

    class Meta:
        db_table = 'ly_banner'
        verbose_name = '轮播广告'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


# 导航栏菜单模型
class Nav(BaseModel):

    POSITION_OPTION = (
        (1, '顶部导航'),
        (2, '底部导航'),
    )
    title = models.CharField(max_length=500, verbose_name='导航标题')
    link = models.CharField(max_length=500, verbose_name='导航链接')
    is_site = models.BooleanField(default=False, verbose_name='是否是站外连接')
    position = models.IntegerField(choices=POSITION_OPTION, default=1, verbose_name='顶部导航栏')

    class Meta:
        db_table = 'ly_nav'
        verbose_name = '导航栏'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title
